package leetcode.part2;

import org.junit.Test;

/**
 * 11. 盛最多水的容器
 * https://leetcode.cn/problems/container-with-most-water/description/?envType=study-plan-v2&envId=top-interview-150
 */
public class S11 {
    public int maxArea(int[] height) {
        int i = 0, j = height.length - 1, res = 0;
        while(i < j) {
            res = height[i] < height[j] ?
                    Math.max(res, (j - i) * height[i++]):
                    Math.max(res, (j - i) * height[j--]);
        }
        return res;


    }



    @Test
    public void test() {
        int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        int[] height1 = {1, 1};
        int[] height2 = {1, 3, 2, 5, 25, 24, 5};
        System.out.println(maxArea(height2));
        System.out.println(maxArea(height));
        System.out.println(maxArea(height1));

    }
}
